﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;

[TestClass()]
public class BullsAndCowsBetaTest
{
    [TestMethod()]
    public void CalculateBullsAndCowsTest()
    {
        int[] number = { 3, 4, 5, 9 };
        string playerChoice = "9547";
        int bulls = 0;
        int cows = 0;
        BullsAndCowsBeta.CalculateBullsAndCows(number, playerChoice, out bulls, out cows);
        Assert.AreEqual(0, bulls);
        Assert.AreEqual(3, cows);
    }

    [TestMethod()]
    public void CheckNumberTrueTest()
    {
        int[] number = { 2, 7, 4, 0 };
        string playerChoice = "2740";
        bool expected = true;
        bool actual;
        actual = BullsAndCowsBeta.CheckNumber(number, playerChoice);
        Assert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void CheckNumberFalseTest()
    {
        int[] number = { 2, 7, 4, 0 };
        string playerChoice = "2840";
        bool expected = false;
        bool actual;
        actual = BullsAndCowsBeta.CheckNumber(number, playerChoice);
        Assert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void GenerateRandomNumberTest()
    {
        int[] actual = BullsAndCowsBeta.GenerateRandomNumber();
        Assert.IsTrue(actual[0] >= 0 && actual[0] <= 9);
        Assert.IsTrue(actual[1] >= 0 && actual[1] <= 9);
        Assert.IsTrue(actual[2] >= 0 && actual[2] <= 9);
        Assert.IsTrue(actual[3] >= 0 && actual[3] <= 9);
    }

    [TestMethod()]
    public void HelpMaxTest()
    {
        int[] number = { 5, 9, 7, 1 };
        HashSet<int> helps = new HashSet<int>();
        helps.Add(3);
        helps.Add(2);
        helps.Add(1);
        helps.Add(0);
        int[] actual = BullsAndCowsBeta.Help(number, helps);
        Assert.AreEqual(null, actual);
    }

    [TestMethod()]
    public void HelpTest()
    {
        int[] number = { 5, 9, 7, 1 };
        HashSet<int> helps = new HashSet<int>();
        helps.Add(3);
        helps.Add(2);
        helps.Add(0);
        int[] actual = BullsAndCowsBeta.Help(number, helps);
        Assert.AreEqual(number[0], actual[0]);
        Assert.AreEqual(number[1], actual[1]);
        Assert.AreEqual(number[2], actual[2]);
        Assert.AreEqual(number[3], actual[3]);
    }


    [TestMethod()]
    public void IsCoorectNumberTrueTest()
    {
        string playerChoice = "6587";
        bool expected = true;
        bool actual;
        actual = BullsAndCowsBeta.IsCorrectNumber(playerChoice);
        Assert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void IsCoorectNumberLongerTest()
    {
        string playerChoice = "65877";
        bool expected = false;
        bool actual;
        actual = BullsAndCowsBeta.IsCorrectNumber(playerChoice);
        Assert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void IsCoorectNumberShorterTest()
    {
        string playerChoice = "587";
        bool expected = false; // TODO: Initialize to an appropriate value
        bool actual;
        actual = BullsAndCowsBeta.IsCorrectNumber(playerChoice);
        Assert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void IsCoorectNumberFalseTest()
    {
        string playerChoice = "dfdf";
        bool expected = false; // TODO: Initialize to an appropriate value
        bool actual;
        actual = BullsAndCowsBeta.IsCorrectNumber(playerChoice);
        Assert.AreEqual(expected, actual);
    }

    /// <summary>
    ///A test for Main
    ///</summary>
    [TestMethod()]
    [DeploymentItem("BullsAndCows.exe")]
    public void MainTest()
    {
        string[] args = null; // TODO: Initialize to an appropriate value
        BullsAndCowsBeta_Accessor.Main(args);
        Assert.Inconclusive("A method that does not return a value cannot be verified.");
    }

    //[TestMethod()]
    //public void PlayGameTest()
    //{
    //    BullsAndCowsBeta.PlayGame();
    //    Assert.Inconclusive("A method that does not return a value cannot be verified.");
    //}

    [TestMethod()]
    public void ShowScoreBoardTest()
    {
        StringWriter consoleWriter = new StringWriter();
        Console.SetOut(consoleWriter);
        BullsAndCowsBeta.ShowScoreBoard();
        string consoleOutput = consoleWriter.ToString();
        Assert.AreEqual("Scoreboard is empty!\r\n", consoleOutput);
    }
}

